import json

class MyJsonEncoder(json.JSONEncoder):
    def default(self, field):
        if isinstance(field, object):
            return field.__dict__

class BaseModel:
    def __new__(cls, *args, **kwargs):
        obj = super().__new__(cls)
        for arg in zip(cls.__annotations__, args):
            setattr(obj, arg[0], arg[1])
        for arg in kwargs:
            setattr(obj, arg, kwargs[arg])
        return obj

    def __str__(self) -> str:
        return json.dumps(self.__dict__, cls=MyJsonEncoder)

class P(BaseModel):
    x: int

class Car(BaseModel):
    a: int
    b: P


car = Car(1, b=P(1))
car.a = 34
print(car)
